package com.kinghood.productcenter.common.model.dto.sku;

import com.kinghood.productcenter.common.model.dto.product.BaseProductSkuEtcDTO;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2024-01-22 11:20
 **/
@Data
public class SkuDTO extends BaseProductSkuEtcDTO implements Serializable {

    private List<BaseProductSkuEtcDTO> extrasList;
    private List<BaseProductSkuEtcDTO> supplierList;

    /**
     * 由于供应链和附件不一定与sku匹配，可能为null，需要剔除
     * */
    public void handNull() {
        if(!CollectionUtils.isEmpty(extrasList)){
            extrasList =  extrasList.stream().filter(x-> Objects.nonNull(x.getId())).collect(Collectors.toList());
        }
        if(!CollectionUtils.isEmpty(supplierList)){
            supplierList =  supplierList.stream().filter(x-> Objects.nonNull(x.getId())).collect(Collectors.toList());
        }
    }
}
